<?php
header("content-type:text/html;charset=utf8");
$usename=$_POST["usename"];
$password=$_POST["password"];
$con=mysqli_connect("localhost","root","root","test");
$sql="select * from user where usename='$usename'";
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_assoc($res);
if($row){
    $arr=[
        "msg"=>"用户名已存在",
        "status"=>3,
    ];
}else{
    $sql="insert into user(usename,password) values('$usename','$password')";
    $res=mysqli_query($con,$sql);
    if($res){
        $arr=[
            "msg"=>"注册成功",
            "status"=>200,
        ];
    }else{
        $arr=[
            "msg"=>"注册失败",
            "status"=>4,
        ];
    }
}
echo json_encode($arr);